j3deditor.bin.hierarchy
Class GeometryManipulator

java.lang.Object
  extended by j3deditor.bin.hierarchy.GeometryManipulator

public class GeometryManipulator
extends java.lang.Object

Tool for manipulating data contained in the specified J3DeGeometryArray.

Author:
Risto Seene
See Also:
J3DeGeometryArray

Field Summary
static int NONE
          Transform mode, specifies that vertices can not be transformed.
static int ROTATE
          Transform mode, specifies that selected vertices can be rotated.
static int SCALE
          Transform mode, specifies that selected vertices can be scaled.
static int TEX_COORDS
          Specifies that the manipulation target of this GeometryManipulator are texture coordinates.
static int TRANSLATE
          Transform mode, specifies that selected vertices can be translated.
static int VERT_COORDS
          Specifies that the manipulation target of this GeometryManipulator are vertex coordinates.
 
Constructor Summary
GeometryManipulator(J3DeGeometryArray geometry, int manipulationTarget)
          Creates an instance of GeometryManipulator which manipulates the data contained in the sepcified J3DeGeometryArray.
 
Method Summary
 boolean addVertex(float x, float y, float z)
          Adds a new vertex to the specified position.
 boolean areFacesSelected()
          Returns true if selected faces array is not null.
 J3DeGeometryArray changeGeometrySize(int newSize)
          Creates and returns new J3DeGeometryArray object with the specified size (vertex data will be also copied to new object).
 void deleteSelectedFaces()
          Deletes selected faces.
 void deselectAllVertices()
          Sets the state of all "selected" vertices to "normal".
 void deselectFaces()
          Deselects all faces.
 void flipFaces()
          Flips the face normals of all selected faces.
 int getAllVertCount()
          Returns the number of vertices the J3DeGeometryArray contains.
 Vertex getCenter()
          Returns a vertex that represents the center of selected vertices.
 J3DeGeometryArray getGeometry()
          Returns the J3DeGeometryArray object which data this GeometryManipulator manipulates.
 int[] getScaleAxes()
          Returns the currently used scale axes multiplicators.
 Vertex[][] getSelectedFaces()
          Returns the array of selected faces.
 float getTexCoord(int axis)
          Returns the texture coordinate value of the specified axis of the first selected vertex if texture coordinates are enabled.
 Vertex[] getTransformableVertices()
          Returns an array that contains all selected vertices.
 int getTransformMode()
          Returns current transform mode.
 Vertex getVertex(int index)
          Returns a vertex at the specified index.
 float getVertexAlpha()
          Returns the alpha component of the vertex color of the first selected vertex if available.
 java.awt.Color getVertexColor()
          Returns the color of the first selected vertex if available.
 int getVertexCount()
          Returns the number of valid vertices.
 boolean hasTexture()
          Returns true if polygonal mesh is able to store texture coordinates.
 void hideSelectedVertices()
          Sets the state of the selected vertices to "hidden".
 void hideVertices(Vertex[] vertices)
          Sets the state of the given vertices to "hidden".
protected  void invertVertices(Vertex[] face)
          Inverts the order of vertices in the specified face.
 boolean isStickyVertsEnabled()
          Returns true if "sticky vertices" is enabled.
 void mergeSelectedVertices()
          Moves all selected vertices to the center of the selection.
protected  void mergeVertices(Vertex[] vertices)
          Moves the specified vertices to the center of the selection.
 void rotateVertices(float rotation, int axis)
          All transformable (selected) vertices are rotated around the specified axis by specified angle.
 void scaleVertices(float scaleChange)
          All transformable (selected) vertices are scaled using the specified value (relatively to selection center).
 void selectFaces(boolean allVerts)
          Selects faces by grouping selected vertices into Vertex[][] array and selecting additional vertices if needed.
 void setScaleAxes(int[] axes)
          Specifies how much polygonal mesh is scaled on each axis when used scaleVertices method.
 void setStickyVertsEnabled(boolean stickyVerts)
          Specifies if the "sticky vertices" is enable or not.
 void setTexCoord(float coordinate, int axis)
          Applies the specified texture coordinate value to all selected vertices on specified axis if texture coordinates are enabled.
 void setTexCoordSet(int set)
          Specifies the texture coordinate set which coordinates can be manipulated if this GeometryManipulator manipulates texture coordinates and geometry has texture coordinates.
 void setTransformMode(int transformMode)
          Specifies the vertex manipulation mode.
 void setVertexAlpha(float alpha)
          Applies the specified alpha component to the vertex color of selected vertices if 4-component vertex color is enabled.
 void setVertexColor(java.awt.Color color)
          Applies the specified color to the selected vertices if vertex color is enabled.
 void showAllVertices()
          Makes all hidden vertices visible.
 void translateVertices(float[] coordinateChange)
          All transformable (selected) vertices are translated using the specified value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONE

public static final int NONE
Transform mode, specifies that vertices can not be transformed.

See Also:
Constant Field Values

TRANSLATE

public static final int TRANSLATE
Transform mode, specifies that selected vertices can be translated.

See Also:
Constant Field Values

ROTATE

public static final int ROTATE
Transform mode, specifies that selected vertices can be rotated.

See Also:
Constant Field Values

SCALE

public static final int SCALE
Transform mode, specifies that selected vertices can be scaled.

See Also:
Constant Field Values

VERT_COORDS

public static final int VERT_COORDS
Specifies that the manipulation target of this GeometryManipulator are vertex coordinates.

See Also:
Constant Field Values

TEX_COORDS

public static final int TEX_COORDS
Specifies that the manipulation target of this GeometryManipulator are texture coordinates.

See Also:
Constant Field Values
Constructor Detail

GeometryManipulator

public GeometryManipulator(J3DeGeometryArray geometry,
                           int manipulationTarget)
Creates an instance of GeometryManipulator which manipulates the data contained in the sepcified J3DeGeometryArray.

Parameters:
geometry - GeometryManipulator which data can be manipulated by this GeometryManipulator
manipulationTarget - specifies which coordinates can be manipulated with translateVertices(), scaleVertices() and rotateVertices() methods.
VERT_COORDS and TEX_COORDS can be used.
Method Detail

setTexCoordSet

public void setTexCoordSet(int set)
Specifies the texture coordinate set which coordinates can be manipulated if this GeometryManipulator manipulates texture coordinates and geometry has texture coordinates.

Parameters:
set - index of texture coordinate set

setScaleAxes

public void setScaleAxes(int[] axes)
Specifies how much polygonal mesh is scaled on each axis when used scaleVertices method.

Parameters:
axes - multiplicator on each axis (3 axes: X, Y and Z)

getScaleAxes

public int[] getScaleAxes()
Returns the currently used scale axes multiplicators.

Returns:
the currently used scale axes multiplicators
See Also:
setScaleAxes(int[] axes)

getGeometry

public J3DeGeometryArray getGeometry()
Returns the J3DeGeometryArray object which data this GeometryManipulator manipulates.

Returns:
the J3DeGeometryArray object which data this GeometryManipulator manipulates

getVertexCount

public int getVertexCount()
Returns the number of valid vertices.

Returns:
the number of valid vertices

getAllVertCount

public int getAllVertCount()
Returns the number of vertices the J3DeGeometryArray contains.

Returns:
the number of vertices the J3DeGeometryArray contains
See Also:
GeometryArray.getVertexCount()

getVertex

public Vertex getVertex(int index)
Returns a vertex at the specified index.

Parameters:
index - index of requested vertex
Returns:
a vertex at the specified index

deselectAllVertices

public void deselectAllVertices()
Sets the state of all "selected" vertices to "normal".


getTransformableVertices

public Vertex[] getTransformableVertices()
Returns an array that contains all selected vertices.

Returns:
an array that contains all selected vertices

getCenter

public Vertex getCenter()
Returns a vertex that represents the center of selected vertices.

Returns:
a vertex that represents the center of selected vertices

getTransformMode

public int getTransformMode()
Returns current transform mode.

Returns:
current transform mode

setTransformMode

public void setTransformMode(int transformMode)
Specifies the vertex manipulation mode. This mode also specifies the active mode of View2D objects which use this GeometryManipulator.

Parameters:
transformMode - new vertex manipulation mode.
NONE - vertices cannot be transformed
TRANSLATE - vertices can be translated
ROTATE - vertices can be rotated
SCALE - vertices can be scaled

translateVertices

public void translateVertices(float[] coordinateChange)
All transformable (selected) vertices are translated using the specified value.

Parameters:
coordinateChange - how much are vertices moved on each axis.
if manipulation target is vertex coordinates: X, Y and Z axes
if manipulation target is texture coordinate: S and T axes

scaleVertices

public void scaleVertices(float scaleChange)
All transformable (selected) vertices are scaled using the specified value (relatively to selection center).

Parameters:
scaleChange - new size of the scalable part of polygonal mesh.
scaleChange < 1 - selected part of the polygonal mesh is made smaller
scaleChange > 1 - selected part of the polygonal mesh is made larger

rotateVertices

public void rotateVertices(float rotation,
                           int axis)
All transformable (selected) vertices are rotated around the specified axis by specified angle. Center of the selected vertices is used.

Parameters:
rotation - rotation angle in radians
axis - 1 - X-axis
2 - Y-axis
3 - Z-axis

isStickyVertsEnabled

public boolean isStickyVertsEnabled()
Returns true if "sticky vertices" is enabled.

Returns:
true if "sticky vertices" are enabled otherwise false
See Also:
setStickyVertsEnabled(boolean stickyVerts)

setStickyVertsEnabled

public void setStickyVertsEnabled(boolean stickyVerts)
Specifies if the "sticky vertices" is enable or not. "Sticky vertices" means that all overlapping vertices are simultaenously selected, otherwise only the closest to camera is selected. Used by VertexManipulator.

Parameters:
stickyVerts - true - enabled; otherwise not
See Also:
VertexManipulator.selectVertex(J3DePoint2D p, Scene2D scene, boolean isShiftDown)

addVertex

public boolean addVertex(float x,
                         float y,
                         float z)
Adds a new vertex to the specified position.

Parameters:
x - X-coordinate of the vertex
y - Y-coordinate of the vertex
z - Z-coordinate of the vertex
Returns:
valid vertex count < vertex count, and the addition of vertex was successful

selectFaces

public void selectFaces(boolean allVerts)
Selects faces by grouping selected vertices into Vertex[][] array and selecting additional vertices if needed.

Parameters:
allVerts - if true only those faces are selected which all vertices are selected, otherwise those faces are selected which have at least one selected vertex

areFacesSelected

public boolean areFacesSelected()
Returns true if selected faces array is not null.

Returns:
true if selected faces array is not null, otherwise false

deselectFaces

public void deselectFaces()
Deselects all faces.


getSelectedFaces

public Vertex[][] getSelectedFaces()
Returns the array of selected faces.

Returns:
the array of selected faces

deleteSelectedFaces

public void deleteSelectedFaces()
Deletes selected faces. Faces must have been selected.


changeGeometrySize

public J3DeGeometryArray changeGeometrySize(int newSize)
Creates and returns new J3DeGeometryArray object with the specified size (vertex data will be also copied to new object). This GeometryManipulator will also uses this new object to manipulate vertex data.

Parameters:
newSize - new size of the polygonal mesh
Returns:
returns new J3DeGeometryArray object with the specified size

hasTexture

public boolean hasTexture()
Returns true if polygonal mesh is able to store texture coordinates.

Returns:
true if polygonal mesh is able to store texture coordinates

hideVertices

public void hideVertices(Vertex[] vertices)
Sets the state of the given vertices to "hidden".

Parameters:
vertices - vertices which state will be changed

hideSelectedVertices

public void hideSelectedVertices()
Sets the state of the selected vertices to "hidden".


showAllVertices

public void showAllVertices()
Makes all hidden vertices visible.


invertVertices

protected void invertVertices(Vertex[] face)
Inverts the order of vertices in the specified face.

Parameters:
face - face which vertices will be inverted

flipFaces

public void flipFaces()
Flips the face normals of all selected faces.


mergeVertices

protected void mergeVertices(Vertex[] vertices)
Moves the specified vertices to the center of the selection.

Parameters:
vertices - vertices which will be merged

mergeSelectedVertices

public void mergeSelectedVertices()
Moves all selected vertices to the center of the selection.


getVertexColor

public java.awt.Color getVertexColor()
Returns the color of the first selected vertex if available.

Returns:
the color of the first selected vertex if available

setVertexColor

public void setVertexColor(java.awt.Color color)
Applies the specified color to the selected vertices if vertex color is enabled.

Parameters:
color - color that will be applied to selected vertices if vertex color is enabled

getVertexAlpha

public float getVertexAlpha()
Returns the alpha component of the vertex color of the first selected vertex if available.

Returns:
the alpha component of the vertex color of the first selected vertex if available

setVertexAlpha

public void setVertexAlpha(float alpha)
Applies the specified alpha component to the vertex color of selected vertices if 4-component vertex color is enabled.

Parameters:
alpha - alpha component which will be applied to the selected vertices

getTexCoord

public float getTexCoord(int axis)
Returns the texture coordinate value of the specified axis of the first selected vertex if texture coordinates are enabled.

Parameters:
axis - axis of the texture coordinates.
Returns:
the texture coordinate value of the specified axis of the first selected vertex if texture coordinates are enabled.

setTexCoord

public void setTexCoord(float coordinate,
                        int axis)
Applies the specified texture coordinate value to all selected vertices on specified axis if texture coordinates are enabled.

Parameters:
coordinate - value which will be applied to all selected vertices
axis - texture coordinate axis: 0 - S, 1 - T, 2 - R, 3 - Q